﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using FluentValidation;
using CashFlow.Admin.Models;

namespace CashFlow.Admin.Validator
{
    public class QueryOrderModelValidator : AbstractValidator<QueryOrderModel>
    {
        public QueryOrderModelValidator()
        {
            RuleFor(x => x.Date).Matches(@"[0-9]{4}\-[0-9]{2}\-[0-9]{2}")
                .WithMessage("日期格式不正确！");
            RuleFor(x => x.Buyer).Matches(@"[\u4e00-\u9fa5a-zA-Z0-9]{2,10}")
                .WithMessage("买家格式不正确！");
            RuleFor(x => x.Seller).Matches(@"[\u4e00-\u9fa5a-zA-Z0-9]{2,10}")
                .WithMessage("卖家格式不正确！");
            RuleFor(x => x.OrderNo).Matches(@"E[0-9]{19,20}")
                .WithMessage("订单号格式不正确！");
            RuleFor(x => x.State).GreaterThanOrEqualTo(0)
                    .LessThanOrEqualTo(3)
                    .WithMessage("订单状态格式不正确！")
                    .When(x => x.State.HasValue);
        }
    }
}